<template>
  <!-- <div id="appbox"></div> -->
  <div id="apptb">
    <div class="grouptitle">
      <div class="grouptitletext">团队信息管理</div>
    </div>

    <div class="contentall">
      <div class="contentallcontent">
        <div class="contentss">
          <!-- 每一行 -->
          <div class="inputall">
            <div class="inputleft">
              <label for="">团队名称</label>
              <input
                type="text"
                class="inputtextte"
                v-model="teamInfo.teamname"
              />
            </div>
            <div class="inputright">
              <label for="">团队简称</label>
              <input
                type="text"
                class="inputtextte"
                v-model="teamInfo.teamabbreviation"
              />
            </div>
          </div>
          <!--  -->
          <div class="inputall">
            <div class="inputleft">
              <label for="">英文名称</label>
              <input
                type="text"
                class="inputtextte"
                v-model="teamInfo.englishname"
              />
            </div>
            <div class="inputright">
              <label for="">分类团队奖</label>
              <!-- <input type="text" /> -->
              <select
                id="categoryAward"
                class="inputtextte"
                v-model="teamInfo.teamaward"
              >
                <option value=""></option>
                <option value="">请选择</option>
                <option value="award1">奖项一</option>
                <option value="award2">奖项二</option>
                <option value="award3">奖项三</option>
              </select>
            </div>
          </div>
          <div class="inputall">
            <div class="inputleft">
              <label for="">州级</label>
              <select
                id="continent"
                class="inputtextte"
                v-model="teamInfo.statelevel"
              >
                <option value="" style="display: none">请选择</option>
                <option value="asia">亚洲</option>
                <option value="europe">欧洲</option>
                <option value="northAmerica">北美洲</option>
              </select>
            </div>
            <div class="inputright">
              <label for="">国家或地区</label>
              <!-- <input type="text" /> -->
              <select
                id="country"
                class="inputtextte"
                v-model="teamInfo.nation"
              >
                <option value="" style="display: none">请选择</option>
                <option value="China">中国</option>
                <option value="USA">美国</option>
                <option value="UK">英国</option>
              </select>
            </div>
          </div>
          <div class="inputall">
            <div class="inputleft">
              <label for="">省级</label>
              <select
                id="province"
                class="inputtextte"
                @click="getcitylist"
                v-model="teamInfo.provinciallevel"
              >
                <option value="" style="display: none">请选择</option>
                <option
                  v-for="item in ProvinceList"
                  :key="item.id"
                  :value="item"
                >
                  {{ item.provincename }}
                </option>
              </select>
            </div>
            <div class="inputright">
              <label for="">市级</label>
              <!-- <input type="text" /> -->
              <select
                id="city"
                class="inputtextte"
                @click="cityChange"
                v-model="teamInfo.cityname"
              >
                <option value="" style="display: none">请选择</option>
                <option
                  :value="item.cityname"
                  v-for="item in CityList"
                  :key="item.id"
                >
                  {{ item.cityname }}
                </option>
              </select>
            </div>
          </div>
          <div class="inputall">
            <div class="inputleft">
              <label for="">详细地址</label>
              <input
                type="text"
                class="inputtextte"
                id="xqdzipt"
                style="width: 538px"
                v-model="teamInfo.address"
              />
            </div>
          </div>
          <div class="inputall">
            <div class="inputleft">
              <label for="">团队负责人</label>
              <input
                type="text"
                class="inputtextte"
                v-model="teamInfo.teamleader"
              />
            </div>
            <div class="inputright">
              <label for="">手机号码</label>
              <input type="text" class="inputtextte" v-model="teamInfo.phone" />
            </div>
          </div>
          <div class="inputall">
            <div class="inputleft">
              <label for="">E-Mall</label>
              <input type="text" class="inputtextte" v-model="teamInfo.emal" />
            </div>
            <div class="inputright">
              <label for="">微信号</label>
              <input type="text" class="inputtextte" v-model="teamInfo.vxid" />
            </div>
          </div>
          <div class="inputall">
            <div class="inputleft">
              <label for="">团队口号</label>
              <input
                type="text"
                class="inputtextte"
                v-model="teamInfo.slogan"
              />
            </div>
            <div class="inputright">
              <label for="">团队照片</label>
              <input type="text" class="inputtextte" v-model="teamInfo.img" />
            </div>
          </div>
          <!-- bottom -->
          <div class="inputall" @click="submitall">
            <div class="bottomimg">
              <img :src="'http://localhost:3002/upload/add.png'" alt="" />
              <span>保存并下一步</span>
            </div>
          </div>
        </div>

        <div class="bottombox"></div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data: function () {
    return {
      ProvinceList: [], // 省份列表
      CityList: [], // 市区列表

      teamInfo: {
        teamname: "", // 团队名称
        teamabbreviation: "", // 团队简称
        englishname: "", // 英文名称
        teamaward: "", // 分类团队奖
        statelevel: "", // 州
        nation: "", // 国
        provinciallevel: "", // 省
        cityname: "", // 市
        address: "", // 详细地址
        teamleader: "", // 团队负责人
        phone: "", // 手机号码
        // 注意：这里应该是 "email" 而不是 "emal"
        email: "",
        vxid: "", // 微信号
        slogan: "", // 团队口号
        img: "", // 团队照片
      },
      errorMessages: [], // 用于收集错误消息的数组
    };
  },
  methods: {
    getcitylist() {
      console.log(this.provinciallevel);
      axios({
        method: "post",
        url: "http://localhost:3002/competition/city/getByid",
        data: { provinceid: this.teamInfo.provinciallevel.provinceid },
      }).then((res) => {
        // console.log(res.data);
        this.CityList = res.data.list;
      });
    },

    getprovincelist() {
      axios({
        method: "post",
        url: "http://localhost:3002/competition/province/list",
      }).then((res) => {
        // console.log(res);
        this.ProvinceList = res.data.list;
      });
    },

    cityChange() {
      console.log("市：" + this.cityname);
    },

    submitall() {
      console.log(
        "团队名称:" + this.teamname,

        "团队简称：" + this.teamabbreviation,

        "英文名称：" + this.englishname,

        "分类团队奖：" + this.teamaward,

        "州：" + this.statelevel,
        "国：" + this.nation,

        "省：" + this.provinciallevel.provincename,
        "市：" + this.cityname,
        "详情：" + this.address,

        "团队负责人：" + this.teamleader,

        "手机号码：" + this.phone,

        "邮箱：" + this.emal,

        "微信号：" + this.vxid,
        "团队口号" + this.slogan,

        "团队照片：" + this.groupimg
      );

      // 遍历对象的每个属性
      // for (var key in this.teamInfo) {
      //   if (
      //     this.teamInfo.hasOwnProperty(key) &&
      //     this.teamInfo[key].trim() === ""
      //   ) {
      //     // 如果属性值为空（或只有空格），则添加到错误消息数组中
      //     this.errorMessages.push(`字段 ${key} 不能为空`);
      //   }
      // }

      // 如果存在错误消息，则显示它们
      // if (this.errorMessages.length > 0) {
      //   alert(this.errorMessages.join("\n")); // 你可以根据需要选择其他方式显示错误消息
      //   return false; // 验证失败，返回false
      // }

      axios({
        method: "post",
        url: "http://localhost:3002/competition/team/add",
        data: this.teamInfo,
      }).then((res) => {
        console.log(res.data);
      });
    },
  },
  mounted() {
    this.getprovincelist();
    // console.log(this.errorMessages);
  },
};
</script>

<style lang="less" scoped>
#apptb {
  background-color: #fff;
  width: 60%;
  height: 85%;
  .grouptitle {
    width: 100%;
    height: 45px;
    background: linear-gradient(#9bcdee, #6190b5);
    color: #fff;
    display: flex;
    justify-content: center; /* 水平居中 */
    align-items: center; /* 垂直居中 */
  }
  .contentall {
    background-color: #74b0e7;
    width: 100%;
    height: 92%;
    padding-top: 6px;
    .contentallcontent {
      width: 98.5%;
      height: 99%;
      background-color: #d5e8fb;
      margin: 0 6px;
      border-radius: 10px;
      position: relative;
      .contentss {
        width: 98%;
        // height: 80%;
        margin: 0 10px;
        background-color: #eef7ff;
        transform: translateY(3%);
        border: 1px solid rgb(206, 200, 200);
        // 每一行
        .inputall {
          background-color: #eef7ff;
          margin: 0px 6px;
          height: 40px;
          font-size: 15px;
          border-bottom: 1px solid rgb(206, 200, 200);
          display: flex;
          align-items: center; /* 垂直居中 */
          select {
            height: 25px;
            width: 227px !important;
          }
          .bottomimg {
            display: flex;
            align-items: center; /* 垂直居中 */
            transform: translateX(220%);
            background: linear-gradient(#f6f6f6, #e1e1e1);
            padding: 4px 10px;
            border-radius: 5px;
            border: 1px solid rgb(174, 171, 171);
            img {
              width: 20px;
              height: 20px;
              margin-right: 8px;
            }
          }

          .inputleft {
            display: inline-block;
            vertical-align: top;
            padding: 0 6px;
            .xqdzipt {
              display: inline-block;
              width: 400px !important;
            }
            label {
              //   padding-right: 5px;
              display: inline-block;
              //   background-color: red;
              width: 80px;
              text-align: center;
            }
            .inputtextte {
              width: 220px;
            }
          }
          .inputright {
            display: inline-block;
            vertical-align: top;
            margin-left: 5px;
            label {
              //   padding-right: 5px;
              display: inline-block;
              //   background-color: red;
              width: 80px;
              text-align: center;
            }
            .inputtextte {
              width: 220px;
            }
          }
        }
      }

      .bottombox {
        background-color: #eef7ff;
        width: 100%;
        height: 38px;
        // transform: translateY(230%);
        position: absolute;
        bottom: 0;
      }
    }
  }
}
</style>